package com.hxht.storage.server.service.quartz.job;

import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerContext;
import org.quartz.SchedulerException;

import com.hxht.storage.server.service.NvrDeviceService;

public class IpchannelUnbindJob extends BaseNvrJob {

	private static Logger quartzLogger = Logger.getLogger(IpchannelUnbindJob.class);
	
	@Override
	protected void executeInternal(JobExecutionContext context)
			throws JobExecutionException {

		//获取JobExecutionContext中的service对象    
        SchedulerContext skedCtx;
		try {
			skedCtx = context.getScheduler().getContext();
			//获取SchedulerContext中的service    
			//这里的service就是通过配置文件 配置的    
			nvrDeviceService = (NvrDeviceService)skedCtx.get("nvrDeviceService");
			boolean unbindResult = nvrDeviceService.unbindIpchannel(sn, channel);
			
			if (unbindResult){
				context.getScheduler().pauseTrigger(context.getTrigger().getKey());     
			    context.getScheduler().unscheduleJob(context.getTrigger().getKey()); 
			    
			    quartzLogger.info("\nipchannel unbind job successed!\n" +
						"sn = " + sn + " / channel = " + channel);
			} else {
				quartzLogger.info("\nipchannel unbind job failed!\n" +
						"sn = " + sn + " / channel = " + channel);
			}
		} catch (SchedulerException e) {
			// TODO Auto-generated catch block
			quartzLogger.error("ipchannel unbind job error!", e);
		}     

	}

}
